package com.yvon.demo;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
@RequestMapping(value = "/oom", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Scope("prototype")
public class OomController {

    int a= 2;

    @Autowired
    private OomService oomService;

    @GetMapping("/thread")
    public String ThreadOom() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 10; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("do some thing");
                }
            });
        }
        return "success";


    }

    @GetMapping("/request1")
    public String request1() {
        int ssss = oomService.ssss();
        a= a+2;
        return "i=" + ssss + "a="+a;
    }
}
